package com.jxwifi.cloud.quickcleanserver.mycenter;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.basicactivity.BasicActivity;
import com.bigkoo.pickerview.TimePickerView;
import com.bumptech.glide.Glide;
import com.jxwifi.cloud.quickcleanserver.R;
import com.jxwifi.cloud.quickcleanserver.app.AccountMgr;
import com.jxwifi.cloud.quickcleanserver.app.CleanBasicActivity;
import com.jxwifi.cloud.quickcleanserver.app.UrlPool;
import com.jxwifi.cloud.quickcleanserver.bean.InfoBean;
import com.jxwifi.cloud.quickcleanserver.okhttp.AuzHttp;
import com.jxwifi.cloud.quickcleanserver.okhttp.DataJson_Cb;
import com.jxwifi.cloud.quickcleanserver.okhttp.Params;
import com.jxwifi.cloud.quickcleanserver.presenter.BrithdayPresenter;
import com.jxwifi.cloud.quickcleanserver.utils.PasswordLogin;
import com.jxwifi.cloud.quickcleanserver.utils.ToastUtils;
import com.jxwifi.cloud.quickcleanserver.view.BrithdayView;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2019/5/20.
 */

public class BirthdayActivity extends CleanBasicActivity implements BrithdayView {

    @Bind(R.id.et_my_personal_data_name)
    TextView mEtMyPersonalData;
    private BrithdayPresenter mPresenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_birthday);
        ButterKnife.bind(this);
        openEventBus();
        initView();
    }

    public void initView() {
        if (!TextUtils.isEmpty(AccountMgr.getBirthday(mBaseContext))){
            mEtMyPersonalData.setText(AccountMgr.getBirthday(mBaseContext));
        }else{
            mEtMyPersonalData.setText("请选择生日");
        }
        mPresenter=new BrithdayPresenter(this);
    }

    @OnClick({R.id.et_my_personal_data_name, R.id.rel_img_back_pressed, R.id.tv_working_confirm})
    void clickCK(View v) {
        switch (v.getId()) {
            case R.id.rel_img_back_pressed:
                onBackPressed();
                break;
            case R.id.et_my_personal_data_name:
                mPresenter.doChoice(mBaseContext);

                break;
            case R.id.tv_working_confirm:
                mPresenter.doBirthday();
                break;
        }
    }

    @Override
    public String getBrithday() {
        return mEtMyPersonalData.getText().toString();
    }

    @Override
    public void onTimeSelect(Date date, View v) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        mEtMyPersonalData.setText(simpleDateFormat.format(date));
    }

    @Override
    public void BrithdaySuccessMsg(int code, String data) {
        if (code == 0) {
            InfoBean mInfoBean = JSON.parseObject(data, InfoBean.class);
            AccountMgr.putUser(mBaseContext, mInfoBean,false);
            finish();
        } else {
            PasswordLogin.passwordlogin(mBaseContext, TAG, AccountMgr.gettell(mBaseContext), AccountMgr.getpassword(mBaseContext));
            if (PasswordLogin.mIsLogin) {
                mPresenter.doBirthday();
            }
        }
    }

    @Override
    public void BrithdayFailureMsg(int errorCode, String msg) {
        Toast toast =Toast.makeText(mBaseContext, msg, Toast.LENGTH_SHORT);
        ToastUtils.showMyToast(toast,3000);
    }

    /**
     * TimePickerView 控件其他属性
     * .setContentSize(18)//滚轮文字大小
     * .setTitleSize(20)//标题文字大小
     * .setTitleText("Title")//标题文字
     *  .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
     *  .isCyclic(true)//是否循环滚动
     *  .setTitleColor(Color.BLACK)//标题文字颜色
     *  .setSubmitColor(Color.BLUE)//确定按钮文字颜色
     *  .setCancelColor(Color.BLUE)//取消按钮文字颜色
     *  .setTitleBgColor(0xFF666666)//标题背景颜色 Night mode
     *   .setBgColor(0xFF333333)//滚轮背景颜色 Night mode
     *   .setDate(selectedDate)// 如果不设置的话，默认是系统时间
     *    .setRangDate(startDate,endDate)//起始终止年月日设定
     *    .setLabel("年","月","日","时","分","秒")//默认设置为年月日时分秒
     *    .isDialog(true)//是否显示为对话框样式
     */
}
